import { defineComponent, provide, ref } from 'vue'
import { RouterView } from 'vue-router'
import { ElConfigProvider as ConfigProvider } from 'element-plus'
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
import en from 'element-plus/lib/locale/lang/en'
import { session } from '@/utils/storage'
export default defineComponent({
  name: 'App',
  setup() {
    const langs: any = ref({
      en: en,
      zhCN: zhCn,
    })
    const paginationLang = ref('zhCN')
    const handleLang = (lang: any) => {
      paginationLang.value = lang
      return lang
    }
    const cacheLang = session.get('lang')
    cacheLang ? handleLang(cacheLang) : (paginationLang.value = 'zhCN')

    provide('handleLang', handleLang)
    return () => (
      <ConfigProvider locale={langs.value[paginationLang.value]}>
        <RouterView />
      </ConfigProvider>
    )
  },
})
